/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using SES.CMS.DO;
/// <summary>
/// Summary description for cmsHoiDapDAL
/// </summary>
namespace SES.CMS.DAL
{

    public class cmsHoiDapDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsHoiDapDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsHoiDapDO objcmsHoiDapDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsHoiDap_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@HoTenNguoiHoi", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsHoiDapDO.HoTenNguoiHoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Email", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsHoiDapDO.Email;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CauHoi", SqlDbType.NText);
            Sqlparam.Value = objcmsHoiDapDO.CauHoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NgayHoi", SqlDbType.DateTime);
            Sqlparam.Value = objcmsHoiDapDO.NgayHoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NguoiTraLoi", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsHoiDapDO.NguoiTraLoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CauTraLoi", SqlDbType.NText);
            Sqlparam.Value = objcmsHoiDapDO.CauTraLoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NgayTraLoi", SqlDbType.DateTime);
            Sqlparam.Value = objcmsHoiDapDO.NgayTraLoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HienThi", SqlDbType.Bit);
            Sqlparam.Value = objcmsHoiDapDO.HienThi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DaTraLoi", SqlDbType.Bit);
            Sqlparam.Value = objcmsHoiDapDO.DaTraLoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsHoiDapDO objcmsHoiDapDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsHoiDap_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@HoiDapID", SqlDbType.Int);
            Sqlparam.Value = objcmsHoiDapDO.HoiDapID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HoTenNguoiHoi", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsHoiDapDO.HoTenNguoiHoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Email", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsHoiDapDO.Email;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CauHoi", SqlDbType.NText);
            Sqlparam.Value = objcmsHoiDapDO.CauHoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NgayHoi", SqlDbType.DateTime);
            Sqlparam.Value = objcmsHoiDapDO.NgayHoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NguoiTraLoi", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsHoiDapDO.NguoiTraLoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CauTraLoi", SqlDbType.NText);
            Sqlparam.Value = objcmsHoiDapDO.CauTraLoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NgayTraLoi", SqlDbType.DateTime);
            Sqlparam.Value = objcmsHoiDapDO.NgayTraLoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HienThi", SqlDbType.Bit);
            Sqlparam.Value = objcmsHoiDapDO.HienThi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DaTraLoi", SqlDbType.Bit);
            Sqlparam.Value = objcmsHoiDapDO.DaTraLoi;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsHoiDapDO objcmsHoiDapDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsHoiDap_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@HoiDapID", SqlDbType.Int);
            Sqlparam.Value = objcmsHoiDapDO.HoiDapID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsHoiDap_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsHoiDapDO Select(cmsHoiDapDO objcmsHoiDapDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsHoiDap_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@HoiDapID", SqlDbType.Int);
            Sqlparam.Value = objcmsHoiDapDO.HoiDapID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["HoiDapID"]))
                    objcmsHoiDapDO.HoiDapID = Convert.ToInt32(dr["HoiDapID"]);
                if (!Convert.IsDBNull(dr["HoTenNguoiHoi"]))
                    objcmsHoiDapDO.HoTenNguoiHoi = Convert.ToString(dr["HoTenNguoiHoi"]);
                if (!Convert.IsDBNull(dr["Email"]))
                    objcmsHoiDapDO.Email = Convert.ToString(dr["Email"]);
                if (!Convert.IsDBNull(dr["CauHoi"]))
                    objcmsHoiDapDO.CauHoi = Convert.ToString(dr["CauHoi"]);
                if (!Convert.IsDBNull(dr["NgayHoi"]))
                    objcmsHoiDapDO.NgayHoi = Convert.ToDateTime(dr["NgayHoi"]);
                if (!Convert.IsDBNull(dr["NguoiTraLoi"]))
                    objcmsHoiDapDO.NguoiTraLoi = Convert.ToString(dr["NguoiTraLoi"]);
                if (!Convert.IsDBNull(dr["CauTraLoi"]))
                    objcmsHoiDapDO.CauTraLoi = Convert.ToString(dr["CauTraLoi"]);
                if (!Convert.IsDBNull(dr["NgayTraLoi"]))
                    objcmsHoiDapDO.NgayTraLoi = Convert.ToDateTime(dr["NgayTraLoi"]);
                if (!Convert.IsDBNull(dr["HienThi"]))
                    objcmsHoiDapDO.HienThi = Convert.ToBoolean(dr["HienThi"]);
                if (!Convert.IsDBNull(dr["DaTraLoi"]))
                    objcmsHoiDapDO.DaTraLoi = Convert.ToBoolean(dr["DaTraLoi"]);

            }
            return objcmsHoiDapDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsHoiDap_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsHoiDapDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsHoiDapDO objcmsHoiDapDO = new cmsHoiDapDO();
                    if (!Convert.IsDBNull(dr["HoiDapID"]))
                        objcmsHoiDapDO.HoiDapID = Convert.ToInt32(dr["HoiDapID"]);
                    if (!Convert.IsDBNull(dr["HoTenNguoiHoi"]))
                        objcmsHoiDapDO.HoTenNguoiHoi = Convert.ToString(dr["HoTenNguoiHoi"]);
                    if (!Convert.IsDBNull(dr["Email"]))
                        objcmsHoiDapDO.Email = Convert.ToString(dr["Email"]);
                    if (!Convert.IsDBNull(dr["CauHoi"]))
                        objcmsHoiDapDO.CauHoi = Convert.ToString(dr["CauHoi"]);
                    if (!Convert.IsDBNull(dr["NgayHoi"]))
                        objcmsHoiDapDO.NgayHoi = Convert.ToDateTime(dr["NgayHoi"]);
                    if (!Convert.IsDBNull(dr["NguoiTraLoi"]))
                        objcmsHoiDapDO.NguoiTraLoi = Convert.ToString(dr["NguoiTraLoi"]);
                    if (!Convert.IsDBNull(dr["CauTraLoi"]))
                        objcmsHoiDapDO.CauTraLoi = Convert.ToString(dr["CauTraLoi"]);
                    if (!Convert.IsDBNull(dr["NgayTraLoi"]))
                        objcmsHoiDapDO.NgayTraLoi = Convert.ToDateTime(dr["NgayTraLoi"]);
                    if (!Convert.IsDBNull(dr["HienThi"]))
                        objcmsHoiDapDO.HienThi = Convert.ToBoolean(dr["HienThi"]);
                    if (!Convert.IsDBNull(dr["DaTraLoi"]))
                        objcmsHoiDapDO.DaTraLoi = Convert.ToBoolean(dr["DaTraLoi"]);
                    arrcmsHoiDapDO.Add(objcmsHoiDapDO);
                }
            }
            return arrcmsHoiDapDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsHoiDap_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable ViewOnWebsite()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsHoiDap_ViewOnWebsite";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
